<?PHP
/*
 * Copyright 2008 by Oliver Radwan, Maxwell Palmer, Nolan McNair,
* Taylor Talmage, and Allen Tucker.  This program is part of RMH Homebase.
* RMH Homebase is free software.  It comes with absolutely no warranty.
* You can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation
* (see <http://www.gnu.org/licenses/ for more information).
*/
/*
 *	personForm.inc
*  shows a form for a person to be added or edited in the database
*	@author Oliver Radwan and Allen Tucker
*	@version 9/1/2008
*/

if ($_SESSION['access_level']==0) {
	echo('<strong>New Volunteer Application Form</strong><br />');
	echo('Please provide us with some basic information about yourself and your interests.' .
		 '<br>When you are finished, hit <b>Submit</b> at the bottom of this page.');
}
else if($_SESSION['access_level']==1)
	if ($_SESSION['_id']!=$person->get_id()){
	echo("<p id=\"error\">You do not have sufficient permissions to edit this user.</p>");
	include('footer.inc');
	echo('</div></div></body></html>');
	die();
}
else {
	echo('<strong>Personnel Edit Form</strong><br />');
	echo('Here you can edit your own information in the database.' .
			'<br>When you are finished, hit <b>Submit</b> at the bottom of this page.');
}
else if ($_SESSION['access_level']==2)
	if ($id=='new') {
	echo('<strong>Personnel Input Form</strong><br />');
	echo('Here you can add a new volunteer into the database. (On this form, "you" means the new person being added.)</p>');
}
else {
	echo('<strong>Personnel Edit Form</strong><br />');
	echo('Here you can edit, delete, or change the password for a volunteer in the database.</p><p>');
}
else {
	echo("<p id=\"error\">You do not have sufficient permissions to add a new person to the database.</p>");
	include('footer.inc');
	echo('</div></div></body></html>');
	die();
}

?>
<form method="POST">
	<input type="hidden" name="old_id" value=<?PHP echo("\"".$id."\"");?>>
	<input type="hidden" name="old_pass"
		value=<?PHP echo("\"".$person->get_password()."\"");?>> <input
		type="hidden" name="_form_submit" value="1">
	<p>
		<span style="font-size: x-small; color: FF0000">*</span> denotes
		required fields <span class="bigTable">
			<table>
				<tr>
					<td>First Name<span style="font-size: x-small; color: FF0000">*</span>:
					</td>
					<td><input type="text" name="first_name" tabindex=1
						value="<?PHP echo($person->get_first_name())?>"></td>
				</tr>
				<tr>
					<td>Last Name<span style="font-size: x-small; color: FF0000">*</span>:
					</td>
					<td><input type="text" name="last_name" tabindex=2
						value="<?PHP echo($person->get_last_name())?>"></td>
				</tr>
				<tr>
					<td>Address<span style="font-size: x-small; color: FF0000">*</span>:
					</td>
					<td><input type="text" name="address" tabindex=3
						value="<?PHP echo($person->get_address())?>"></td>
				</tr>
				<tr>
					<td>City<span style="font-size: x-small; color: FF0000">*</span>:
					</td>
					<td><input type="text" name="city" tabindex=4
						value="<?PHP echo($person->get_city())?>"></td>
				</tr>
				<tr>
					<td>State, Zip<span style="font-size: x-small; color: FF0000">*</span>:
					</td>
					<td><select name="state" tabindex=5>
							<?PHP

							$states = array("AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA",
					        "KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM",
					        "NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA",
					        "WV","WI","WY");
			foreach ($states as $st) {
				echo "<option value='" . $st . "' ";
				if($person->get_state() == $st ) echo("SELECTED");
				else if ($id == "new" && $st =="ME") echo("SELECTED");
				echo ">" . $st . "</option>";
			}
			?>
					</select>, <input type="text" name="zip" size="5" tabindex=6
						value="<?PHP echo($person->get_zip())?>"></td>
				</tr>
				<tr>
					<td>Primary Phone<span style="font-size: x-small; color: FF0000">*</span>:
					</td>
					<td><input type="text" name="phone1" MAXLENGTH=12 tabindex=7
						value="<?PHP echo($person->get_phone1())?>"></td>
				</tr>
				<tr>
					<td>Alternate Phone:</td>
					<td><input type="text" name="phone2" MAXLENGTH=12 tabindex=8
						value="<?PHP echo($person->get_phone2())?>"></td>
				</tr>
				<tr>
					<td>Email:</td>
					<td><input type="text" name="email" tabindex=9
						value="<?PHP echo($person->get_email())?>"></td>
				</tr>
				<tr>
					<td>Employer</td>
					<td><input type="text" name="employer" tabindex=9
						value="<?PHP echo($person->get_employer())?>"></td>
				</tr>
				<tr>
					<td>Contact Person</td>
					<td><input type="text" name="contact_person" tabindex=9
						value="<?PHP echo($person->get_contact_person())?>"></td>
				</tr>
				<tr>
					<td>Contact Phone</td>
					<td><input type="text" name="contact_phone" MAXLENGTH=12 tabindex=7
						value="<?PHP echo($person->get_contact_phone())?>"></td>
				</tr>

				<tr>
					<td>Birthday:</td>
					<td><?PHP
					echo('<select name="DateOfBirth_Month">');
					echo('<option value=""></option>');
					$months = array('','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
					for ($i = 1; $i <= 12; $i++) {
            if ($i < 10) {
            	echo '<option value=0'.$i;
            	if (substr($person->get_birthday(),1,1)==="$i") echo(' SELECTED');
            	echo '>' . $months[$i] . ' </option>';
            }
            else {
            	echo '<option value=0'.$i;
            	if (substr($person->get_birthday(),0,2)==="$i") echo(' SELECTED');
            	echo '>' . $months[$i] . ' </option>';
            }
        }
        ?> </select> <select name="DateOfBirth_Day">
							<option value=""></option>
							<?PHP
							for ($i = 1; $i <= 31; $i++) {
            	if ($i < 10)
            	{
            		echo '<option value=0'.$i; if(substr($person->get_birthday(),4,1)==="$i") echo(' SELECTED'); echo '>' . $i . ' </option>';
            	}
            	else
            	{ echo '<option value='.$i; if(substr($person->get_birthday(),3,2)==="$i") echo(' SELECTED'); echo '>' . $i . ' </option>';
            	}
            }
            ?>

					</select> <select name="DateOfBirth_Year">
							<option value=""></option>
							<?PHP
							$start_year = date("Y");
							for ($i = $start_year; $i >= ($start_year-80); $i--){
         	    if ($i > 1999 && $i < 2010)
         	    {
         	    	echo '<option value=0'.substr($i,3,1); if(substr($person->get_birthday(),7,1)===substr($i,3,1)) echo(' SELECTED'); echo '>' . $i . ' </option>';
         	    }
         	    else
         	    { echo '<option value='.substr($i,2,2); if(substr($person->get_birthday(),6,2)===substr($i,2,2)) echo(' SELECTED'); echo '>' . $i . ' </option>';
         	    }
            }
            ?>
					</select>
					</td>
				</tr>


				<tr>
					<td>Volunteer Start Date:</td>
					<td><select name="DateOfStart_Month">
							<option value=""></option>
							<?PHP
							$months = array('','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
							for ($i = 1; $i <= 12; $i++) {
           	    if ($i < 10)
            	   {
            	   	echo '<option value=0'.$i; if(substr($person->get_start_date(),0,2)==="0"."$i") echo(' SELECTED'); echo '>' . $months[$i] . ' </option>';
            	   }
                else
                { echo '<option value=0'.$i; if(substr($person->get_start_date(),0,2)==="$i") echo(' SELECTED'); echo '>' . $months[$i] . ' </option>';
                }
            }
            ?>
					</select> <select name="DateOfStart_Day">
							<option value=""></option>
							<?PHP
							for ($i = 1; $i <= 31; $i++) {
            	if ($i < 10)
            	{
            		echo '<option value=0'.$i; if(substr($person->get_start_date(),3,2)==="0"."$i") echo(' SELECTED'); echo '>' . $i . ' </option>';
            	}
            	else
            	{ echo '<option value='.$i; if(substr($person->get_start_date(),3,2)==="$i") echo(' SELECTED'); echo '>' . $i . ' </option>';
            	}
            }
            ?>
					</select> <select name="DateOfStart_Year">
							<option value=""></option>
							<?PHP
							$start_year = date("Y");
							for ($i = $start_year; $i >= ($start_year-80); $i--){
            	if ($i > 1999 && $i < 2010)
            	{
            		echo '<option value=0'.substr($i,3,1); if(substr($person->get_start_date(),7,1)===substr($i,3,1)) echo(' SELECTED'); echo '>' . $i . ' </option>';
            	}
            	else
            	{ echo '<option value='.substr($i,2,2); if(substr($person->get_start_date(),6,2)===substr($i,2,2)) echo(' SELECTED'); echo '>' . $i . ' </option>';
            	}
            }
            ?>
					</select>
					</td>
				</tr>
			</table>
		</span>
		<?PHP
		$st = implode(',',$person->get_type());
		$newpersontypes = array('applicant'=>'Not sure', 'sub'=>'Sub', 'volunteer'=>'House volunteer (3-4 hour shift weekdays or weekends)',
					'family_room'=>'Family Room volunteer (3 hour in-hospital shift)',
                   	'weekend_volunteer'=>'Weekend volunteer (need a pair from Friday 5pm to Sunday 3pm, usually twice a year)',
					'tab_top_volunteer'=>'Tab top volunteer (pick-up, delivery)',
					'house_cleaner'=>'House cleaner (weekdays or weekends)',
                   	'errand_runner'=>'Errand runner (weekdays)',
					'guest_chef'=>'Guest chef (dinners, weekend brunches, or holiday dinners)');
    $types = array('applicant'=>'Applicant', 'sub'=>'Sub', 'volunteer'=>'House volunteer', 'family_room'=>'Family Room volunteer',
                   'weekend_volunteer'=>'Weekend volunteer', 'tab_top_volunteer'=>'Tab top volunteer', 'house_cleaner'=>'House cleaner',
                   'errand_runner'=>'Errand runner', 'guest_chef'=>'Guest chef', 'manager'=>'Manager' );
    if ($_SESSION['access_level']==0) {
	     echo('<p>Please check below all position type(s) for which you are applying:');
	     $ts = $newpersontypes;
    }
    else {
		 echo('<p>Position type(s) for this person:');
		 $ts = $types;
	}
	echo('<span style="font-size:x-small;color:FF0000">*</span><br>');

	foreach ($ts as $key=>$value) {
    	echo ('<input type="checkbox" name="type[]" value=' . $key);
    	if (strpos($st,$key)!==false) echo(' CHECKED');
    	echo ('>' . $value . '<br />');
    }

    echo('<p><strong>Status: </strong> <select name="status">');
    echo ('<option value="active"');
    if ($person->get_status()=="active") echo (" SELECTED");
    echo ('>active</option>');
    echo ('<option value="inactive"');
    if ($person->get_status()=="inactive") echo (" SELECTED");
    echo ('>inactive</option></select>');
    ?>
	</p>
	<p>
		<strong>Availability<span style="font-size: x-small; color: FF0000">*</span>
		</strong> (required only for Sub, House and Family Room volunteer
		positions) <span class="bigTable">
			<table>
				<tr>
					<td></td>
					<td>Monday</td>
					<td>Tuesday</td>
					<td>Wednesday</td>
					<td>Thursday</td>
					<td>Friday&nbsp;&nbsp;&nbsp;</td>
					<td>Saturday</td>
					<td>Sunday</td>
				</tr>
				<?PHP
				$shifts = array('9-12'=>'3 hours morning<br />(9-12 or 10-1)', '12-15'=>'3 hours early afternoon<br />(12-3 or 1-4)', '15-18'=>'3 hours late afternoon<br />(3-6, 4-7, or 2-5)',
                    '18-21'=>'3 hours evening<br />(6-9 or 5-9)', 'night'=>'overnight');
    $days = array('Mon', 'Tue', 'Wed' , 'Thu', 'Fri', 'Sat', 'Sun');
    $person_availability = implode(',',$person->get_availability());
    foreach ($shifts as $shiftkey => $shiftvalue) {
       echo ('<tr><td>'. $shiftvalue .'</td>');
       foreach ($days as $day) {
       	  $realkey = key_if_scheduled($day, $shiftkey);
       	  if ($realkey!=="") {
    	      echo ('<td><input type="checkbox" name="availability[]" value=' . $realkey);
    	      if (strpos($person_availability,$realkey)!==false) echo(' CHECKED');
    	      echo ('></td>');
       	  }
       	  else echo ('<td></td>');
       }
       echo ('</tr>');
    }
    // This little function returns the proper key if the shift is scheduled -- the
    // currect day and hours that need to be scheduled.  If no shift is scheduled for
    // that day and shift, the function returns "".
    function key_if_scheduled($day, $shiftkey) {
    	$result = $day . $shiftkey;
    	if ($day=="Sat")
    		if ($shiftkey=="9-12")
    		$result = "Sat10-1";
    	else if ($shiftkey=="12-15")
    		$result = "Sat1-4";
    	else if ($shiftkey=="night")
    		return $result;
    	else $result = "";
    	else if ($day=="Sun")
    		if ($shiftkey=="9-12")
    		return $result;
    	else if ($shiftkey == "15-18")
    		$result = "Sun2-5";
    	else if ($shiftkey=="18-21")
    		$result = "Sun5-9";
    	else $result = "";
    	else if ($day=="Fri")
    		if ($shiftkey=="18-21")
    		$result = "";
    	else if ($shiftkey=="night")
    		return $result;
    	if ($shiftkey=="night")
    		$result = "";
    	return $result;
    }
    ?>
			</table>
		</span>
	</p>
	<p>
		<?PHP
		if($id == 'new' || strpos(implode(',',$person->get_type()),'applicant') !== false) {
		  echo('<br>List the places and dates of any past/current volunteer experiences and responsibilities.<br />');
		  echo('<textarea name="experience" rows="3" cols="60">');
		  echo($person->get_experience());
		  echo('</textarea>');

		  echo('<p>Why are you interested in volunteering at the Ronald McDonald House (RMH)?<br />');
		  echo('<textarea name="motivation" rows="3" cols="60">');
		  echo($person->get_motivation());
		  echo('</textarea>');

		  echo('<p>Do you have any special talents, interests, or skills you would like to bring to RMH?<br />');
		  echo('<textarea name="specialties" rows="3" cols="60">');
		  echo($person->get_specialties());
		  echo('</textarea>');

		  echo('<p>Have you ever been convicted of a felony, misdemeanor, or child abuse?  ' .
	      		'<br>(Policy requires background checks for all RMH volunteers.)<br />');
	      echo('<textarea name="convictions" rows="2" cols="60">');
	      echo($person->get_convictions());
	      echo('</textarea>');

	      echo('<p>List the states where you have lived during the last five years.<br />');
	      echo('<textarea name="wherelived" rows="2" cols="60">');
	      echo($person->get_wherelived());
	      echo('</textarea>');

	      echo('<p>What else would you like us to know about you?<br />');
	      echo('<textarea name="my_notes" rows="3" cols="60">');
	      echo($_POST['my_notes']);
	      echo('</textarea>');
		}
		if($_SESSION['access_level']>=2){
			if (strpos(implode(',',$person->get_type()),'applicant') !== false) {
					echo('<p> <strong>Applicant Status</strong><table>' .
				   		' <tr><td><input type="checkbox" name="background_check" value="yes" ');
					if($person->get_background_check()=='yes')
						echo("CHECKED");
					echo ('></td>');
					echo ('<td>Background Check Cleared</td></tr>' .
						' <tr><td><input type="checkbox" name="interview" value="yes" ');
					if($person->get_interview()=='yes')
						echo("CHECKED");
					echo('></td><td>Interview Completed</td></tr>' .
						' <tr><td><input type="checkbox" name="shadow" value="yes"  ');
					if($person->get_shadow()=='yes') echo("CHECKED");
					echo('></td><td>Shadow Completed</td></tr></table> ');
			}
			echo('<p><strong>Private Notes</strong> - notes visible only to the House Manager.<br />');
			echo('<textarea name="private_notes" rows="3" cols="60">');
			echo($person->get_private_notes());
			echo('</textarea>');
		}
		if ($_SESSION['access_level']>=1) {
	  	    		echo('<p><strong>Public Notes</strong> - notes from the House Manager to the volunteer or applicant. <br />');
	  	    		echo('<textarea name="public_notes" rows="3" cols="60"');
	  	    		if($_SESSION['access_level']==1)
	  	    			echo(' disabled="true"');
	  	    		echo('>'. $person->get_public_notes() . '</textarea>');
	  	    		if (strpos(implode(',',$person->get_type()),'applicant') === false) {
	  	    		echo ('<p><strong> Notes</strong> - correspondence between the volunteer and the House Manager.<br />');
	  	    		echo('<textarea name="my_notes" rows="3" cols="60">');
	  	    		echo($person->get_my_notes());
	  	    		echo('</textarea>');
              }
		}

		echo('<input type="hidden" name="schedule" value="'.implode(',',$person->get_schedule()).'">');
		echo('<input type="hidden" name="history" value="'.implode(',',$person->get_history()).'">');
		echo('<input type="text" name="password" value="'.$person->get_password().')">');
		echo('<input type="hidden" name="_submit_check" value="1"><p>');
		if ($_SESSION['access_level']==0)
			echo('Hit <input type="submit" value="Submit" name="Submit Edits"> to complete this application.<br /><br />');
		  else
		     echo('Hit <input type="submit" value="Submit" name="Submit Edits"> to submit these edits.<br /><br />');
		  if ($id != 'new' && $_SESSION['access_level']>=2) {
			echo ('<input type="checkbox" name="deleteMe" value="DELETE"> Check this box and then hit ' .
				'<input type="submit" value="Delete" name="Delete Entry"> to delete this entry. <br />' .
				'<input type="checkbox" name="reset_pass" value="RESET"> Check this box and then hit ' .
				'<input type="submit" value="Reset Password" name="Reset Password"> to reset this user\'s password.</p>');
		}
		?>

</form>
